Page({
  data: {
    isDefault: false,
    region: [], // 选中的数据
    user:'',
    show:false
        
    
  },
  onDefaultChange: function (event) {
    this.setData({
      isDefault: event.detail.value
    });
  },
  onShow(){
      this.setData({
show:true
      })
  },
  
  onLoad(){
      console.log('sds')
this.setData({
    user:getApp().globalData.user
})
console.log(this.data.user)



 let out=[];
 out.push(
     this.data.user.province,
     this.data.user.city,
     this.data.user.district
 )
 this.setData({
     region:out
 })
 

  
},
 
  bindKeyInputUsername(e){
this.setData({
    'user.username':e.detail.value
})
  },
  bindKeyInputPhoneNumber(e){
    this.setData({
        'user.phoneNumber':e.detail.value
    })
      },
      bindKeyInputAdress(e){
        this.setData({
            'user.address':e.detail.value
        })
          },
  bindRegionChange: function (e) {
    console.log(e.detail.value)
    console.log(e.detail.code)
    this.setData({
      region: e.detail.value,
     


    })
    this.setData({
        'user.province':this.data.region[0],
        'user.city':this.data.region[1],
        'user.district':this.data.region[2]
    })
    
  },
  onbutton: function () {
      
      let url=getApp().globalData.URL+'/users/updateInfo'
      let data=this.data.user
      console.log(data)
      getApp().wxRequest('POST',url,data,(res)=>{
        
          if(res.statusCode==200){
              console.log(res.data)
              // 返回上一页并关闭本页面
wx.navigateBack({
    delta: 1 // delta 参数表示返回的页面数，1 表示返回上一页
  });
          }
      }),(err)=>{
          console.log('出错了！')
      }
    
  }
});